﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using static VisionCloud.Core.Model.Ms.TaskPoints;

namespace VisionCloud.Domain.DtoModel.Ms
{
    public class SystemHealthDto
    {
        public HealthDto DriveHealth { get; set; }

        public HealthDto NetworkHealth { get; set; }

        public HealthDto PowerHealth { get; set; }

        public HealthDto VisionServerHealth { get; set; }

        /// <summary>
        /// 用于存放框架的任务站点最新数据
        /// </summary>
        public TaskInFrameDto TaskInFramework { get; set; } = new TaskInFrameDto();

        /// <summary>
        /// 用于同步数据库中的站点最新数据
        /// </summary>
        public TaskInDatabaseDto TaskInDatabase { get; set; } = new TaskInDatabaseDto();

        /// <summary>
        /// 存放人工测量项报告的生成状态
        /// </summary>
        public ManualReportInFrameDto ManualReportInFramework { get; set; } = new ManualReportInFrameDto();
    }

    /// <summary>
    /// 健康状态
    /// </summary>
    public class HealthDto
    {
        /// <summary>
        /// 是否健康
        /// </summary>
        public bool Health { get; set; }

        /// <summary>
        /// 状态消息
        /// </summary>
        public string Msg { get; set; }
    }

    public class TaskInFrameDto
    {
        public string SessionID { get; set; }

        /// <summary>
        /// 是否健康
        /// </summary>
        public bool Health { get; set; }

        /// <summary>
        /// 状态消息
        /// </summary>
        public string Msg { get; set; }

        /// <summary>
        /// 任务ID
        /// </summary>
        public Guid TaskID { get; set; }

        /// <summary>
        /// 记录时间
        /// </summary>
        public DateTime DateTime { get; set; }

        /// <summary>
        /// 任务点状态
        /// </summary>
        public List<TaskPointInVisionServer> TaskPointList { get; set; } = new List<TaskPointInVisionServer>();

        /// <summary>
        /// 不符合质量要求的点
        /// </summary>
        public JArray IsUnqualifiedIndexList { get; set; }

        /// <summary>
        /// 框架启动时间
        /// </summary>
        public string MeasureInitTime { get; set; }
    }

    public class TaskInDatabaseDto
    {
        /// <summary>
        /// 任务ID
        /// </summary>
        public Guid TaskID { get; set; }

        /// <summary>
        /// 记录时间
        /// </summary>
        public DateTime DateTime { get; set; }

        /// <summary>
        /// 任务点状态
        /// </summary>
        public List<TaskPointInDb> TaskPointList { get; set; } = new List<TaskPointInDb>();
    }

    public class TaskPointInDb
    {
        public Guid TaskId { get; set; }
        public int Index { get; set; }
        public PointStatus Status { get; set; }

        public string StatusText
        {
            get
            {
                return Status.ToString();
            }
        }

        public DateTime DateTime { get; set; }

        /// <summary>
        /// 完成实测值录入否,0:未完成，1：已完成
        /// </summary>
        public bool IsManualMeasureInput { get; set; }
    }

    public enum StatusEnum
    { waitting = 10, running = 20, success = 30, error = 40 }

    public class TaskPointInVisionServer
    {
        public string Index { get; set; }
        public string SubIndex { get; set; }

        public string ParentIndex { get; set; }

        public string TaskInfoDateTime
        {
            get
            {
                if (TaskInfoDateTimeMilli != null)
                {
                    return TaskInfoDateTimeMilli.ToString("yyyy-MM-dd HH:mm:ss.fff");
                }
                return DateTime.MinValue.ToString("yyyy-MM-dd HH:mm:ss.fff");
            }
        }

        public DateTime TaskInfoDateTimeMilli { get; set; }
        public decimal Percent { get; set; }

        /// <summary>
        /// 能否开始点击测量
        /// 1.数据库状态是开始测量状态
        /// 2.框架中的状态是已经成功
        /// 3.框架中的状态是已经失败
        /// </summary>
        public bool CanStartMeasure
        {
            get
            {
                if (StatusInDb == PointStatus.开始测量
                    && (StatusInFrame == StatusEnum.success || StatusInFrame == StatusEnum.error)
                    )
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

        /// <summary>
        /// 数据库中的状态
        /// </summary>
        public PointStatus StatusInDb { get; set; }

        /// <summary>
        /// 框架中的状态
        /// </summary>
        public StatusEnum StatusInFrame { get; set; }

        public string StatusInFrameText
        {
            get
            {
                return StatusInFrame.ToString();
            }
        }

        public string TaskInfoStep { get; set; }

        public string CollectionDatetime { get; set; }
        public string CollectionStatus { get; set; }
        public string CollectionMessage { get; set; }
        public string CollectionProgress { get; set; }

        public string ComputeDatetime { get; set; }
        public string ComputeStatus { get; set; }
        public string ComputeMessage { get; set; }
        public string ComputeProgress { get; set; }

        public string ReportDatetime { get; set; }
        public string ReportStatus { get; set; }
        public string ReportMessage { get; set; }
        public string ReportProgress { get; set; }

        public string Msg { get; set; }

        public string IsSubPoint { get; set; }

        public string PretreatDatetime { get; set; }
        public string PretreatStatus { get; set; }
        public string PretreatMessage { get; set; }
        public string PretreatProgress { get; set; }
    }

    public class ManualReportTaskPoint
    {
        public int Index { get; set; }
        public string ReportDatetime { get; set; }
        public string ReportStatus { get; set; }
        public string ReportMessage { get; set; }
        public string ReportProgress { get; set; }

        /// <summary>
        /// 是否完成人工测量项录入
        /// </summary>
        public bool IsManualMeasureInput { get; set; }
    }

    /// <summary>
    /// 人工测量项报告实体
    /// </summary>
    public class ManualReportInFrameDto
    {
        /// <summary>
        /// 状态消息
        /// </summary>
        public string Msg { get; set; }

        /// <summary>
        /// 任务ID
        /// </summary>
        public Guid TaskID { get; set; }

        /// <summary>
        /// 记录时间
        /// </summary>
        public DateTime DateTime { get; set; }

        /// <summary>
        /// 任务点状态
        /// </summary>
        public List<ManualReportTaskPoint> TaskPointList { get; set; } = new List<ManualReportTaskPoint>();

        public bool IsEnable { get; set; } = true;

        ///// <summary>
        ///// 不符合质量要求的点
        ///// </summary>
        //public JArray IsUnqualifiedIndexList { get; set; }

        ///// <summary>
        ///// 框架启动时间
        ///// </summary>
        //public string MeasureInitTime { get; set; }
    }
}